package com.jadesoft.ciadapter.plugin;

import com.jadesoft.ciadapter.plugin.base.DefaultAction;
import com.jadesoft.ciadapter.plugin.base.Pluggable;
import com.jadesoft.ciadapter.plugin.base.PluginAction;
import com.jadesoft.ciadapter.plugin.base.PluginManager;

public class LyricPlugin implements Pluggable {

	public void init(Object container) {

		PluginAction lyricContent = new DefaultAction() {
			public Object exec(Object... args) {
				String chosen = my_hello_dolly_get_lyric();
				return "<p id='my_dolly'>"+chosen+"</p>";
			}
		};
		PluginManager.addAction("after_content", lyricContent,container);
		
		PluginAction lyricCss = new DefaultAction() {
			public Object exec(Object... args) {
				return "<style type='text/css'>"+
						"#my_dolly {"+
						"	color:#5681A7;"+
						"	position: absolute;"+
						"	top: .3em;"+
						"	margin: 0;"+
						"	padding: 0;"+
						"	right: 115px;"+
						"	font-size: 11px;"+
						"}"+
						"</style>";
			}
		};
		PluginManager.addAction("head", lyricCss,container);
		
		

	}
	
	private String my_hello_dolly_get_lyric() {
		/** These are the lyrics to Hello Dolly */
		String lyrics = "Leave me out with the waste  |	This is not what I do  |	It's the wrong kind of place  To be thinking of you  |	It's the wrong time  For somebody new  |	It's a small crime  And I've got no excuse  |	Is that alright?  Give my gun away when it's loaded  |	Is that alright?  If u don't shoot it how am I supposed to hold it  |	Is that alright?  Give my gun away when it's loaded  |	Is that alright  With you?  |	Leave me out with the waste  |	This is not what I do  |	It's the wrong kind of place To be cheating on you  |	It's the wrong time  She's pulling me through  |	It's a small crime  And I've got no excuse  |	Is that alright?  I give my gun away when it's loaded  |	Is that alright?  If you dont shoot it, how am I supposed to hold it  |	Is that alright?  I give my gun away when it's loaded  |	Is that alright?  Is that alright with you?  |	Is that alright?  I give my gun away when it's loaded  |	Is that alright? |	If you don't shoot it, how am I supposed to hold it  |	Is that alright?  |	If I give my gun away when it's loaded  |	Is that alright?  Is that alright with you?  |	Is that alright?  |	Is that alright?  Is that alright with you?  |	Is that alright?  |	Is that alright?  Is that alright with you? ";

		// Here we split it into lines
		String[] lyricsArray = lyrics.split("\\|");

		// And then randomly choose a line
		return lyricsArray[ (int)(Math.random()*(lyricsArray.length - 1)) ] ;
	}

}
